package com.bootdo.kaoqin.thread;

import com.bootdo.common.utils.DateUtils;
import com.bootdo.kaoqin.domain.KaoqinCallGroup;
import com.bootdo.kaoqin.domain.KaoqinConfig;
import com.bootdo.kaoqin.service.KaoqinCallGroupService;
import com.bootdo.kaoqin.service.KaoqinConfigService;
import com.bootdo.kaoqin.service.KaoqinOrderService;
import com.bootdo.kaoqin.service.KaoqinUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

//@Component
public class ComputeThread  {
    @Autowired
    private KaoqinConfigService kaoqinConfigService;
    @Autowired
    private KaoqinOrderService kaoqinOrderService;
    @Autowired
    private KaoqinCallGroupService kaoqinCallGroupService;
    @Autowired
    private KaoqinUserService kaoqinUserService;

    @Scheduled(cron="0 0 1 * * ?")   //每天1点执行
    // @Scheduled(fixedRate = 1000)
    public void TestFunction(){
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        Date now = calendar.getTime();
        String  nowTimeFromt =  DateUtils.format(now, DateUtils.DATE_PATTERN);
        List<KaoqinCallGroup> kaoqinCallGroups =  kaoqinCallGroupService.list(new HashMap<>());
        for(KaoqinCallGroup kaoqinCallGroup : kaoqinCallGroups){
            TaskRunnerPool.run(new HjbTask(ComputeThread.this,kaoqinCallGroup,nowTimeFromt));
        }
    }



    public KaoqinConfigService getKaoqinConfigService() {
        return kaoqinConfigService;
    }

    public KaoqinOrderService getKaoqinOrderService() {
        return kaoqinOrderService;
    }

    public KaoqinCallGroupService getKaoqinCallGroupService() {
        return kaoqinCallGroupService;
    }

    public KaoqinUserService getKaoqinUserService() {
        return kaoqinUserService;
    }
}
